<div class="modal-dialog" role="document">
    <div class="modal-content">
        <div class="modal-header">
            <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
            <h4 class="modal-title" id="exampleModalLabel">编辑</h4>
        </div>
        <form style="margin:4%;" id="editForm" data-toggle="validator" >
            <input type="hidden" name="id" value="{$industryInfo.id}">
            <div class="form-group">
                <label for="name" class="control-label"><span style="color:red;">*</span>行业名称:</label>
                <input type="text" id="name" class="form-control" value="{$industryInfo.name}" name="name" required>
            </div>
            <div class="form-group">
                <label for="introduce" class="control-label">描述:</label>
                <input type="text" id="introduce" class="form-control" value="{$industryInfo.introduce}" name="introduce" required>
            </div>
            <div class="form-group">
                <label for="message-text" class="control-label">状&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;态:</label>
                <input type="checkbox" name="status" value="{$industryInfo.status}" />
            </div>
        </form>
        <div class="modal-footer">
            <button type="button" data-dismiss="modal" class="btn btn-default">取消</button>
            <button type="button" id="SaveBtn" class="btn btn-primary">保存</button>
        </div>
    </div>
</div>
<script type="text/javascript">
    var status = "{$industryInfo.status}";
    $(function () {
        $('#editForm').validator();
        var switchOption = {
            onText: "开",
            offText: "关",
            onColor: "success",
            offColor: "info",
            state: true,
            onSwitchChange: function (event, state) {
                if (state == true) {
                    $(this).val("1");
                } else {
                    $(this).val("0");
                }
            }

        };
        if(status == "0"){
            switchOption.state = false;
        }else{
            switchOption.state = true;
        }
        $("input:checkbox[name='status']").bootstrapSwitch(switchOption);

    })
    $("#SaveBtn").click(function () {
        var validator = $("#editForm").data("bs.validator");
        validator.validate();
        if (!validator.hasErrors()){
            $.ajax({
                url: "{:U('Admin/Org/doAdd')}",
                type: "post",
                dataType: "json",
                data: {'name':$('[name=name]').val(),
                    'status':$('[name=status]').val(),
                    'id':$('[name=id]').val(),
                    'introduce':$('[name=introduce]').val()},
                success: function (data) {
                    $("#commonModal").modal('toggle');
                    common.alert("提示", '编辑成功', function () {
                        common.reload();
                    });
                }
            })
        }
    })
</script>